package com.edu.exam.enums.examination;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 审核结果枚举
 * 管理申请审核的结果状态
 *
 * @author System
 * @version 1.0.0
 */
public enum ReviewResult implements BaseEnum {

    APPROVE("APPROVE", "批准", 1),
    REJECT("REJECT", "拒绝", 2),
    PENDING("PENDING", "待处理", 3);

    private final String code;
    private final String description;
    private final int order;

    ReviewResult(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public int getOrder() {
        return order;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static ReviewResult fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Review result code cannot be null or empty");
        }

        for (ReviewResult result : values()) {
            if (result.getCode().equals(code)) {
                return result;
            }
        }
        throw new IllegalArgumentException("Unknown review result code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static ReviewResult fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Review result description cannot be null or empty");
        }

        for (ReviewResult result : values()) {
            if (result.getDescription().equals(description)) {
                return result;
            }
        }
        throw new IllegalArgumentException("Unknown review result description: " + description);
    }
}